<?php
include ("checkvalid.php");

$id = $checkRow['id'];
$newname = $_POST['newname'];
$stuid = $_POST['stuid'];
$age = $_POST['age'];
$sex = $_POST['sex'];
$sign = $_POST['signature'];
$haspic = $_POST['haspic'];
if ($newname == "") {
	$newname = $checkRow['name'];
}
if ($stuid == "") {
	$stuid = $checkRow['studentid'];
}
if ($age == "-1") {
	$age = $checkRow['age'];
}
if ($sex == "-1") {
	$sex = $checkRow['sex'];
}
$sql = "update userinfo set name='$newname', studentid='$stuid', age=$age, sex=$sex, signature='$sign' where id=$id";
if (mysql_query($sql)) {
	echo "success info";
	if ($haspic == 'true'){
		$uploads_dir = "C:\\PHPWAMP\\wwwroot\\phpprojects\\userimage";
    
        if ((($_FILES["file"]["type"] == "image/jpeg")
            || ($_FILES["file"]["type"] == "image/jpg")
            || ($_FILES["file"]["type"] == "image/png"
            )))
        {
            if ($_FILES["file"]["error"] > 0)
            {
                die("Return Code: " . $_FILES["file"]["error"]);
            }
            else
            {
                $name = basename($_FILES["file"]["name"]);
                $extension = pathinfo("$uploads_dir/$name", PATHINFO_EXTENSION);
                move_uploaded_file($_FILES["file"]["tmp_name"],
                    $uploads_dir."\\".$id.'.jpg');
				$url = "userimage/".$id.".jpg";
				mysql_query("update userinfo set image='$url' where id=$id");
				echo " and image"; 
            }
        }
        else
        {
            die("Invalid file");
        }
	}
} else {
	echo "fail";
}